package com.example.poemtest.index.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ListView;

import com.example.poemtest.Activity.BottomNavigationViewActivity;
import com.example.poemtest.R;
import com.example.poemtest.index.entity.PoetryVideo;
import com.example.poemtest.index.adapter.PoetryVideoAdapter;
import com.example.poemtest.utils.Constant;
import com.example.poemtest.utils.FullScreenUtil;
import com.google.android.exoplayer2.util.Log;

import java.util.ArrayList;
import java.util.ConcurrentModificationException;
import java.util.List;

/**
 * 诗词大会的视频页面
 */
public class PoetryVideoActivity extends AppCompatActivity {

    private ImageView next;
    private ListView listView;
    private List<PoetryVideo> poetryVideoList;
    private PoetryVideoAdapter poetryVideoAdapter;
    private AdapterView.OnItemClickListener onItemClickListener;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        FullScreenUtil.getInstance().fullScreen(this,true);
        setContentView(R.layout.activity_poetry_video);
        setView();
        //设置数据源
//        poetryVideoList = setData();
        poetryVideoAdapter = new PoetryVideoAdapter(
                this,
                Constant.videoPoetries,
                R.layout.layout_poetry_video
        );
        //为gridView绑定适配器
        listView.setAdapter(poetryVideoAdapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(PoetryVideoActivity.this, PoetryVideoDetailActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("video_name",Constant.videoPoetries.get(position).getVideoName());
                bundle.putString("video_src",Constant.videoPoetries.get(position).getVideoSrc());
                intent.putExtras(bundle);
                startActivity(intent);
            }
        });
        next.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(PoetryVideoActivity.this, BottomNavigationViewActivity.class);
                intent.putExtra("id",1);
                startActivity(intent);
            }
        });
    }

    /**
     * 设置数据源
     */
    private List<PoetryVideo> setData() {
        List<PoetryVideo> list = new ArrayList<>();
        PoetryVideo poetryVideo = new PoetryVideo();
        poetryVideo.setPoetryVideoImg("http://hn-bkt.clouddn.com/img/7.jpg");
        poetryVideo.setPoetryVideoTitle("诗词大会第一季");
        poetryVideo.setPoetryVideoAddress("http://hn-bkt.clouddn.com/12-%E7%AC%AC%E5%85%AB%E5%AD%A3%E7%AC%AC%E5%8D%81%E6%9C%9F.mp4");
        list.add(poetryVideo);
        PoetryVideo poetryVideo1 = new PoetryVideo();
        poetryVideo1.setPoetryVideoImg("http://hn-bkt.clouddn.com/img/7.jpg");
        poetryVideo1.setPoetryVideoTitle("诗词大会第二季");
        poetryVideo1.setPoetryVideoAddress("http://hn-bkt.clouddn.com/12-%E7%AC%AC%E5%85%AB%E5%AD%A3%E7%AC%AC%E5%8D%81%E6%9C%9F.mp4");
        list.add(poetryVideo1);
        PoetryVideo poetryVideo2 = new PoetryVideo();
        poetryVideo2.setPoetryVideoImg("http://hn-bkt.clouddn.com/img/7.jpg");
        poetryVideo2.setPoetryVideoTitle("诗词大会第三季");
        poetryVideo2.setPoetryVideoAddress("http://hn-bkt.clouddn.com/12-%E7%AC%AC%E5%85%AB%E5%AD%A3%E7%AC%AC%E5%8D%81%E6%9C%9F.mp4");
        list.add(poetryVideo2);
        PoetryVideo poetryVideo3 = new PoetryVideo();
        poetryVideo3.setPoetryVideoImg("http://hn-bkt.clouddn.com/img/7.jpg");
        poetryVideo3.setPoetryVideoTitle("诗词大会第四季");
        poetryVideo3.setPoetryVideoAddress("http://hn-bkt.clouddn.com/12-%E7%AC%AC%E5%85%AB%E5%AD%A3%E7%AC%AC%E5%8D%81%E6%9C%9F.mp4");
        list.add(poetryVideo3);
        PoetryVideo poetryVideo4 = new PoetryVideo();
        poetryVideo4.setPoetryVideoImg("http://hn-bkt.clouddn.com/img/7.jpg");
        poetryVideo4.setPoetryVideoTitle("诗词大会第五季");
        poetryVideo4.setPoetryVideoAddress("http://hn-bkt.clouddn.com/12-%E7%AC%AC%E5%85%AB%E5%AD%A3%E7%AC%AC%E5%8D%81%E6%9C%9F.mp4");
        list.add(poetryVideo4);
        return list;
    }

    /**
     * 绑定控件对剑
     */
    private void setView() {
        next = findViewById(R.id.back);
        listView = findViewById(R.id.poetry_video_grid_view);
        listView.setOnItemClickListener(onItemClickListener);
    }
}